package com.chapter.sample.redis.iomultiplex.bio.read;

import cn.hutool.core.util.IdUtil;

import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class RedisServiceBIO {
    public static void main(String[] args) throws IOException {
        ServerSocket serverSocket = new ServerSocket(6389);
        while (true){
            System.out.println("---------111 等待连接");
            Socket socket = serverSocket.accept(); //阻塞1,等待客户端连接
            System.out.println("---------222 等待连接");

            InputStream inputStream = socket.getInputStream();
            int length = -1;
            byte[] bytes = new byte[1024];
            System.out.println("---------333 等待读取");
            while ((length = inputStream.read(bytes)) != -1) { //阻塞2，等待客户端发送数据
                System.out.println("----------444 读取成功" + new String(bytes,0,length));
                System.out.println("============== "+ IdUtil.simpleUUID());
                System.out.println();

            }
            inputStream.close();
            socket.close();
        }
    }
}
